// 版权归 瞄你个汪 所有。使用本代码应遵守相关法律法规和Apache 2.0开源许可要求。
package top.geeke.database.seed;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.DbType;
import org.springframework.core.env.Environment;
import top.geeke.constants.AppConstPool;
import top.geeke.entity.SysTenant;
import top.geeke.eunm.SysStatusEnum;
import top.geeke.eunm.SysTenantTypeEnum;
import top.geeke.toolkit.SpringBeanManager;
import top.geeke.toolkit.supertable.seed.SuperSeedData;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 系统租户表种子数据
 * </p>
 *
 * @author 瞄你个汪
 * @since 2024/5/26 8:13
 */
public class SysTenantSeedData implements SuperSeedData<SysTenant> {
    @Override
    public List<SysTenant> getSeedData() {
        Environment env = SpringBeanManager.getBean(Environment.class);
        String primaryDBName = env.getProperty("spring.datasource.dynamic.primary");
        String jdbcUrl = env.getProperty("spring.datasource.dynamic.datasource." + primaryDBName + ".url");
        return new ArrayList<SysTenant>(){{
            add(newInstance(AppConstPool.PRIMARY_ID, AppConstPool.PRIMARY_ID, 1300000000101L, 1300000000111L, "geeke","edu.geeke.top", SysTenantTypeEnum.ID, DbType.MYSQL, jdbcUrl, primaryDBName, "2099-12-30 00:00:00", "系统默认"));
        }};
    }

    public SysTenant newInstance(Long id, Long appId, Long orgId, Long userId, String code, String host, SysTenantTypeEnum tenantType,
                                 DbType dbType, String connection, String configId, String expiredDate, String remark) {
        SysTenant sysTenant = new SysTenant();
        sysTenant.setId(id);
        sysTenant.setCode(code);
        sysTenant.setAppId(appId);
        sysTenant.setOrgId(orgId);
        sysTenant.setUserId(userId);
        sysTenant.setHost(host);
        sysTenant.setTenantType(tenantType);
        sysTenant.setDbType(dbType);
        sysTenant.setConnection(connection);
        sysTenant.setConfigId(configId);
        sysTenant.setExpiredDate(DateUtil.parseLocalDateTime(expiredDate));
        sysTenant.setRemark(remark);
        sysTenant.setStatus(SysStatusEnum.Enabled);
        return sysTenant;
    }
}
